package com.open.basic.util;

import com.open.basic.exception.BizException;
import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.Collections;


public class AssertUtil {

    private AssertUtil(){
        throw new AssertionError("No com.open.basic.util.AssertUtil instances for you!");
    }

    public static void assertTrue(boolean expression, String message) {
        if (!expression) {
            throw new BizException(message);
        }
    }

    public static void assertTrue(boolean expression) {
        assertTrue(expression, "[Assertion failed] - this expression must be true");
    }

    public static void notNull(Object object, String message) {
        if (object == null) {
            throw new BizException(message);
        }
    }

    public static void notNull(Object object) {
        if (object == null) {
            throw new BizException("the object is null");
        }
    }

    public static void notEmpty(Collection<?> collection, String message) {
        if (CollectionUtils.isEmpty(collection)) {
            throw new BizException(message);
        }
    }
}
